/**
 * Created by aixin on 2018/12/12.
 */
import Vue from 'vue';
import Vuex from 'vuex';

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        history: [], // 存储已经打开过的页面集合
        tagsList: [], // 存储所有的页签
        currentTags: [], // 存储当前展示的页签
        tagsIndex: 0, // 当前展示页签第一个在tagsList中的index

        tabsList: [], // 存储所有的页签
        userId: null, // 用户id
        isLogin: false, // 是否已经登录
        userInfo: {
            menuList: [],
            userName: '',
            token: ''
        }
    },
    mutations: {
        setHistory (state, history) { // 保存history方法
            state.history = history;
        },
        setTagsList (state, tagsList) { // 保存tagsList方法
            state.tagsList = tagsList;
        },
        setCurrentTags (state, tags) { // 保存currentTags方法
            state.currentTags = tags;
        },
        setTagsIndex (state, index) { // 保存tagsIndex方法
            state.tagsIndex = index;
        },

        setTabsList (state, tabsList) { // 保存tagsList方法
            state.tabsList = tabsList;
        },
        setUserInfo (state, userInfo = {menuList: [], userName: '', token: ''}) {
            state.userInfo = userInfo;
        },
        setUserId (state, id) {
            state.userId = id;
        },
        setIsLogin (state, b) {
            state.isLogin = b;
        }
    },

    getters: {
        tabsList: state => state.tabsList,
        userInfo: state => state.userInfo,
        userId: state => state.userId,
        isLogin: state => state.isLogin
    }
});

export default store;
